package com.wangxiang.shop.product.controller;

import java.util.*;


import com.wangxiang.shop.product.dao.SkuDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wangxiang.shop.product.entity.SkuEntity;
import com.wangxiang.shop.product.service.SkuService;
import com.wangxiang.common.utils.PageUtils;
import com.wangxiang.common.utils.R;



/**
 * 
 *
 * @author wangxiang
 * @email 2293672863@qq.com
 * @date 2022-04-02 11:30:17
 */
@RestController
@RequestMapping("product/sku")
public class SkuController {
    @Autowired
    private SkuService skuService;
    @Autowired
    private SkuDao skuDao;

    //远程调用接口，通过sku_id查询sku数据（sku_id）
    @RequestMapping("getSkuBySkuIdList")
    public List<SkuEntity> getSkuList(@RequestBody List<Integer> list){
//        System.out.println("远程接口接受数据"+list);
        List<SkuEntity> skuList = skuService.getSkuList(list);
        return skuList;

    }

    //远程接口调用，给改变spu,sku库存
    @RequestMapping("update/ware")
    public void updateWare(@RequestBody List<HashMap<String,Integer>> maps){
        skuService.updateWare(maps);
    }
    @RequestMapping("order")
    public List<HashMap<String , String>> order(@RequestBody List<HashMap<String, Integer>> list){
        List<HashMap<String, String>> order = skuService.order(list);
        return order;
    }

    @RequestMapping("paynow")
    public int paynow(@RequestBody HashMap<String,String> map){
        int skuId = skuService.paynow(map);
        return skuId;
    }
    @RequestMapping("updateWareByPayNow")
    public int updateWareByPayNow(@RequestBody HashMap<String , Integer> map){
        int i = skuService.updateWareByPayNow(map);
        return i;
    }

    @RequestMapping("mysql")
    public R mysqldata(){
        ArrayList<SkuEntity> skuEntities = new ArrayList<>();
        for (int i = 1; i < 3101213+1; i++) {
            SkuEntity skuEntity = skuDao.selectById(i);
            if (skuEntity!=null){
                skuEntities.add(skuEntity);
            }
            if (skuEntity==null){
                System.out.println("id:"+i+"为空");
            }

        }
        return R.ok().put("list",skuEntities);
    }

}
